package com.longg.service.impl;

import com.longg.dao.UserFocusDao;
import com.longg.model.UserFocus;
import com.longg.service.IUserFocusService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserFocusServiceImpl implements IUserFocusService {
    private UserFocusDao userFocusDao = new UserFocusDao();

    @Override
    public int deleteById(int id) {
        return userFocusDao.deleteById(id);
    }

    @Override
    public int focus(int uid, String fuid) {
        UserFocus userFocus = new UserFocus();
        userFocus.setUserId(uid);
        userFocus.setUserFocusId(Integer.parseInt(fuid));
        return userFocusDao.save(userFocus);
    }

    @Override
    public UserFocus ifFocus(int uid, int fuid) {
        Map<String,Object> map = new HashMap<>();
        map.put("user_id",uid);
        map.put("user_focus_id",fuid);
        List<UserFocus> and = userFocusDao.findByCols("and", map);
        if (and.isEmpty()){
            return null;
        }
        return and.get(0);
    }

    @Override
    public List<Map<String, Object>> findFocus(int id,int page) {
        return userFocusDao.findAllById(id,page);
    }

    @Override
    public long getFocusCount(int id) {
        return userFocusDao.getFocusCount(id);
    }


}
